package com.hung.dao;

import com.hung.entity.Report;
import com.hung.pojo.Matter;
import com.hung.util.orm.annotations.Delete;
import com.hung.util.orm.annotations.Insert;
import com.hung.util.orm.annotations.Select;
import com.hung.util.orm.annotations.Update;

import java.util.List;

/**
 * 操作瓜圈事件
 *
 * @author Hung
 */
public interface MatterDao {

    /**
     * 根据mid获取事件详细信息
     *
     * @param mid
     * @return
     */
    @Select("select id,pid,uid,postTime,commentId,praise,content from matter where id=?")
    Matter queryMatterById(Integer mid);

    /**
     * 发表事件
     *
     * @param matter
     * @return
     */
    @Insert("insert matter(id, pid, uid, postTime, commentId, praise, content) values (default,#{pid},#{uid},#{postTime},default,0,#{content})")
    Integer addMatter(Matter matter);

    /**
     * 根据uid和mid查询是否点赞
     *
     * @param uid
     * @param mid
     * @return
     */
    @Select("select uid from praise where uid=? and mid=?")
    Integer isPraise(Integer uid, Integer mid);

    /**
     * 根据uid和mid查询是否收藏
     *
     * @param uid
     * @param mid
     * @return
     */
    @Select("select uid from collect where uid=? and mid=?")
    Integer isCollected(Integer uid, Integer mid);

    /**
     * 点赞
     *
     * @param uid
     * @param mid
     * @return
     */
    @Insert("insert into praise (uid, mid) VALUES (?,?)")
    Integer praise(Integer uid, Integer mid);

    /**
     * 收藏
     *
     * @param uid
     * @param mid
     * @return
     */
    @Insert("insert into collect (uid, mid) VALUES (?,?)")
    Integer favorite(Integer uid, Integer mid);

    /**
     * 取消赞
     *
     * @param uid
     * @param mid
     * @return
     */
    @Delete("delete from praise where uid=? and mid =?")
    Integer cancelPraise(Integer uid, Integer mid);

    /**
     * 取消收藏
     *
     * @param uid
     * @param mid
     * @return
     */
    @Delete("delete from collect where uid=? and mid =?")
    Integer cancelFavorite(Integer uid, Integer mid);

    /**
     * 举报事件
     *
     * @param mid
     * @param pid
     * @return
     */
    @Insert("insert into report (id, mid,pid) VALUES (DEFAULT,?,?)")
    Integer report(Integer mid, Integer pid);

    /**
     * 查找所有举报事件
     *
     * @return
     */
    @Select("select id,mid,pid from report;")
    List<Report> queryAllReports();

    /**
     * 根据mid删除事件
     *
     * @param mid
     * @return
     */
    @Delete("delete from matter where id=?")
    Integer deleteMatterById(Integer mid);

    /**
     * 根据uid查询所有赞过的事件
     *
     * @param uid
     * @return
     */
    @Select("select mid from praise where uid=?")
    List<Integer> queryAllPraiseById(Integer uid);

    /**
     * 根据uid查询所有赞过的事件
     *
     * @param uid
     * @return
     */
    @Select("select mid from collect where uid=?")
    List<Integer> queryAllFavoriteById(Integer uid);

    /**
     * 增加赞的数目
     *
     * @param mid
     * @return
     */
    @Update("update matter set praise=praise+1 where id=?")
    Integer addPraise(Integer mid);

    /**
     * 减少赞的数目
     *
     * @param mid
     * @return
     */
    @Update("update matter set praise=praise-1 where id=?")
    Integer reducePraise(Integer mid);

    /**
     * 删除举报
     * @param id
     * @return
     */
    @Delete("delete from report where id=?;")
    Integer deleteReport(Integer id);
}

